package database
 // https://github.com/go-pg/pg.git
 //
import (
	"git.oschina.net/fanbuchi/redpack/domain"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	"log"
)


//var dialect="postgres"
//var args= "postgresql://root@localhost:26257?application_name=cockroach&dbname=redpack&sslmode=disable"
var dialect="mysql"
//username:password@protocol(address)/dbname?param=value
//本地测试地址
//var args="root:nBFdzDj_N2_9gp2@tcp(localhost:3306)/red_pack?charset=utf8&parseTime=True&loc=Local"
//线上测试外网访问地址
//var args="root:nBFdzDj_N2_9gp2@tcp(cdb-7v9uyeq5.gz.tencentcdb.com:10028)/red_pack?charset=utf8&parseTime=True&loc=Local"
//线上测试内网访问地址
var args="root:nBFdzDj_N2_9gp2@tcp(10.0.0.4:3306)/red_pack?charset=utf8&parseTime=True&loc=Local"


var master *gorm.DB
func init() {
	db, err := gorm.Open(dialect,args)
	if err !=nil{
		log.Fatal(err)
	}

	db.AutoMigrate(&domain.Account{},
	&domain.Profile{},
	&domain.RedPack{},
	&domain.Oauth{},
	&domain.Wallet{},
	&domain.WalletLog{},
	)
	master=db
}

func Master() *gorm.DB{
	return master.Debug()
}